/**
 * @param {number[][]} grid
 * @return {number}
 */
export var projectionArea = function (grid) {
  let [xyView, xzView, yzView] = [0, 0, 0]
  let yMax = []
  for (let i = 0; i < grid.length; i++) {
    let xMax = 0
    for (let j = 0; j < grid[i].length; j++) {
      if (grid[i][j] > 0) {
        xyView++
      }
      if (grid[i][j] > xMax) {
        xMax = grid[i][j]
      }
      yMax[j] = Math.max(yMax[j] || 0, grid[i][j])
    }
    xzView += xMax
  }
  yzView = yMax.reduce((a, b) => a + b)
  return xyView + xzView + yzView
}
